<template>
	<div>
		<div class="h2">分值管理</div>
		<!-- <div id="components-form-demo-advanced-search">
			<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch">
				<a-row :gutter="24">
					<a-col :span="8">
						<a-form-item label="关键字">
							<a-input autocomplete="off" class="field-right" placeholder="请输入关键字搜索"
								v-decorator="[`key`]" />
						</a-form-item>
					</a-col>
					<a-col :span="8" style="margin-top:4px;">
						<a-button type="primary" html-type="submit" class="btn1">搜索</a-button>
						<a-button :style="{ marginLeft: '8px' }" @click="handleReset" class="btn2">重置</a-button>
					</a-col>
				</a-row>
			</a-form>
		</div> -->
		<div class="option">
			<a-button type="primary" class="btn" @click="addList">新增</a-button>
		</div>
		<div>
			<el-table :data="data" row-key="ID" default-expand-all v-loading="loading" border :max-height="tableHeight"
				highlight-current-row style="width: 100%;">
				<el-table-column prop="ActivityLevelName" label="级别" min-width="100"></el-table-column>
				<el-table-column prop="Score" label="参与者分值" width="120">
					<template slot-scope="scope">
						<a-tag color="green">{{ scope.row.JoinScore?scope.row.JoinScore:'暂无' }}</a-tag>
					</template>
				</el-table-column>
				
				<el-table-column prop="Score" label="观众分值" width="100">
					<template slot-scope="scope">
						<a-tag color="green">{{ scope.row.AudienceScore?scope.row.AudienceScore:'暂无' }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="Score" label="工作人员分值" width="140">
					<template slot-scope="scope">
						<a-tag color="green">{{ scope.row.WorkerScore?scope.row.WorkerScore:'暂无' }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="Score" label="是否允许申请" width="140">
					<template slot-scope="scope">
						<a-tag :color="scope.row.IsAgreeApply?'green':'red'">{{ scope.row.IsAgreeApply?'是':'否' }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="Score" label="是否允许发起" width="140">
					<template slot-scope="scope">
						<a-tag :color="scope.row.IsAgreeCreate?'green':'red'">{{ scope.row.IsAgreeCreate?'是':'否' }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="Score" label="是否允许发放" width="140">
					<template slot-scope="scope">
						<a-tag :color="scope.row.IsAgreeSend?'green':'red'">{{ scope.row.IsAgreeSend?'是':'否' }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="Score" label="是否自定义分数" width="140">
					<template slot-scope="scope">
						<a-tag :color="scope.row.ApplyCustomScore?'green':'red'">{{ scope.row.ApplyCustomScore?'是':'否' }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="AddTime" label="添加时间" min-width="200"></el-table-column>
				<el-table-column label="操作" width="220">
					<template slot-scope="scope">
						<oprateBtn title="修改" icon="icon-editor1" color="#1890FF"
							@tap="modifyList(scope.row, 'modify')"></oprateBtn>
						<oprateBtn title="删除" icon="icon-delete" color="red" @tap="deleteList(scope.row)"></oprateBtn>
					</template>
				</el-table-column>
			</el-table>
		</div>
		<add :text="text" :LevelList="LevelList" :ClubTypeList="ClubTypeList" v-show="addIf" @closeFun="closeFun"></add>
	</div>
</template>

<script>
	import add from './add';
	import Func from '@/utils/func';
	import {
		ManageActivityTypeScoreDoGetList,
		ManageActivityTypeScoreDoDelete,
		GetActivityTypeList,
		GetActivityLevelListCommon
	} from '@/api/follow';
	const data = [];
	export default {
		components: {
			add
		},
		data() {
			return {
				data,
				form: this.$form.createForm(this, {
					name: 'advanced_search'
				}),
				pagination: {
					currentPage: 1,
					pageSize: this.global.pageSize,
					pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
					showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
				},
				LevelList:[],
				addIf: false,
				text: {},
				visible: false,
				confirmLoading: false,
				itemId: '',
				departmentList: [],
				worklist: [],
				loading: false,
				values: {},
				ClubTypeList: [],
				tableHeight: parseFloat(window.innerHeight - 160)
			};
		},
		computed: {},
		created() {
			this.getList()
			this.getOtherList()
		},
		mounted() {},
		methods: {
			async getOtherList() {
				let res1 = await GetActivityLevelListCommon()
				this.LevelList = res1.data.data
				let res = await GetActivityTypeList()
				this.ClubTypeList = res.data.data
			},
			handleSearch(e) {
				e.preventDefault();
				this.form.validateFields((error, values) => {
					this.pagination.currentPage = 1;
					this.values = values;
					this.getList();
				});
			},
			handleReset() {
				this.form.resetFields();
				this.values = {};
				this.getList();
			},
			handleSizeChange(val) {
				this.pagination.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				this.pagination.currentPage = val;
				this.getList();
			},
			async getList() {
				this.loading = true;
				let data = {};
				if (this.values) {
					data = this.values;
				}
				data.activityTypeID=this.$route.query.activityTypeID;
				let res = await ManageActivityTypeScoreDoGetList(data);
				this.loading = false;
				this.data = this.toTree(res.data.data)
			},
			toTree(data) {
				let result = [];
				let map = {};
				if (!Array.isArray(data)) {
					return [];
				}
				data.forEach(item => {
					map[item.ID] = item;
				});
				data.forEach(item => {
					let parent = map[item.ParentID];
					if (parent) {
						(parent.children || (parent.children = [])).push(item);
					} else {
						result.push(item);
					}
				});
				return result;
			},
			addList() {
				this.text = {};
				this.addIf = !this.addIf;
			},
			modifyList(text) {
				text = Object.assign(text, {
					time: new Date()
				});
				this.addIf = !this.addIf;
				this.text = text;
			},
			deleteList(text) {
				let that = this
				this.$confirm({
					title: '提示',
					content: `您确定删除该类型吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {}
						data.id = text.ID
						let res = await ManageActivityTypeScoreDoDelete(data);
						if (res.data.code == 0) {
							that.getList()
							that.$message.success(res.data.msg)
						} else {
							that.$message.error(res.data.msg)
						}
					}
				})
			},
			seeList(text, name) {
				this.$router.push({
					name: name,
					query: {
						activityTypeID: text.ID,
						Name: text.Name
					}
				});
			},
			setFlow(text) {
				let path = ''
				path = 'ApplyActivityFlow'
				this.$router.push({
					name: path,
					query: {
						clubTypeID: text.ID
					}
				});
			},
			handleCancel(e) {
				this.visible = false;
			},
			closeFun() {
				this.addIf = false;
				this.getList();
			}
		}
	};
</script>

<style lang="less" scoped>
	.home-form /deep/.ant-form-item {
		display: flex;
		margin-bottom: 10px !important;


	}

	.home-form /deep/.ant-form-item-label {
		width: 80px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		text-align: right;
	}

	.home-form /deep/.ant-form-item-control-wrapper {
		flex: 1;
	}

	/deep/.el-table th.is-leaf {
		background: #fafafa;
	}

	/deep/.el-table td,
	/deep/.el-table th {
		padding: 5px;
	}

	.option {
		margin-top: 10px;
		margin-bottom: 20px;
		overflow: hidden;
	}

	.option .btn {
		height: 36px;
		line-height: 36px;
		padding: 0 10px;
		float: left;
		background: #1890ff;
		color: #fff;
		margin-right: 10px;
		border-radius: 3px;
		cursor: pointer;
		border: none;
	}

	.foot {
		text-align: center;
		margin-top: 100px;
	}

	.el-pagination {
		margin-top: 10px;
	}

	/deep/.el-table td .cell,
	/deep/.el-table th .cell {
		text-align: left !important;
	}
</style>
